package com.neusoft.student.utils;

/**
 * @Author: duan
 * @Date: Create in 14:21 2020/10/22
 */
public class Pager {
    /**
     * 表数据的总数
     */
    private int count;
    /**
     * 当前显示的记录数量
     */
    private int pageSize = 5;
    /**
     * 当前页码
     */
    private int pageNum = 1;
    /**
     * 总页数
     */
    private int pageTotal;

    public Pager(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCount() {
        return count;
    }

    public Pager setCount(int count) {
        this.count = count;
        setPageTotal();
        return this;
    }

    public int getPageSize() {
        return pageSize;
    }

    public Pager setPageSize(int pageSize) {
        this.pageSize = pageSize;
        return this;
    }

    public int getPageNum() {
        return pageNum;
    }

    public Pager setPageNum(int pageNum) {
        this.pageNum = pageNum;
        return this;
    }

    public int getPageTotal() {
        return pageTotal;
    }

    /**
     * 计算分页总数
     */
    private void setPageTotal() {
        if (count <= pageSize) {
            this.pageTotal = 1;
        } else {
            if (count % pageSize == 0) {
                //整除
                this.pageTotal = count / pageSize;
            } else {
                this.pageTotal = count / pageSize + 1;
            }
        }
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Pager{");
        sb.append("count=").append(count);
        sb.append(", pageSize=").append(pageSize);
        sb.append(", pageNum=").append(pageNum);
        sb.append(", pageTotal=").append(pageTotal);
        sb.append('}');
        return sb.toString();
    }
}
